//
//  NSDate+Tool.m
//  01-黑马微博
//
//  Created by lanou3g on 15/9/16.
//  Copyright (c) 2015年 heima. All rights reserved.
//

#import "NSDate+Tool.h"

@implementation NSDate (Tool)
/**是不是今年*/
- (BOOL)isThisYear{
    //日历对象
    NSCalendar *calendar = [NSCalendar currentCalendar];
    NSCalendarUnit unit = NSCalendarUnitYear;
    //获得某个时间的年月日时分秒
    NSDateComponents *dateCmps = [calendar components:unit fromDate:self];
    NSDateComponents *nowCmps = [calendar components:unit fromDate:[NSDate date]];
    return dateCmps.year == nowCmps.year;
}
/**是不是昨天*/
- (BOOL)isYesterday{
    NSDateFormatter *fmt = [[NSDateFormatter alloc] init];
    fmt.dateFormat = @"yyyy-MM-dd";
    NSDate *now = [NSDate date];
    NSString *createStr = [fmt stringFromDate:self];
    NSString *nowStr = [fmt stringFromDate:now];
    NSDate *createDate = [fmt dateFromString:createStr];
    now = [fmt dateFromString:nowStr];
    //日历对象
    NSCalendar *calendar = [NSCalendar currentCalendar];
    NSCalendarUnit unit = NSCalendarUnitYear | NSCalendarUnitMonth | NSCalendarUnitDay;
    //计算两个日期的差值
    NSDateComponents *cmps = [calendar components:unit fromDate:createDate toDate:now options:0];
    return cmps.year == 0 && cmps.month == 0 && cmps.day == 1;
}
/**是不是今天*/
- (BOOL)isToday{
    NSDateFormatter *fmt = [[NSDateFormatter alloc] init];
    fmt.dateFormat = @"yyyy-MM-dd";
    NSDate *now = [NSDate date];
    NSString *createStr = [fmt stringFromDate:self];
    NSString *nowStr = [fmt stringFromDate:now];
    NSDate *createDate = [fmt dateFromString:createStr];
    now = [fmt dateFromString:nowStr];
    //日历对象
    NSCalendar *calendar = [NSCalendar currentCalendar];
    NSCalendarUnit unit = NSCalendarUnitYear | NSCalendarUnitMonth | NSCalendarUnitDay;
    //计算两个日期的差值
    NSDateComponents *cmps = [calendar components:unit fromDate:createDate toDate:now options:0];
    return cmps.year == 0 && cmps.month == 0 && cmps.day == 0;
    
}

@end
